package com.eco.controller;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.eco.entity.FishType;
import com.eco.service.FishTypeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
 * @author: xulinyu
 * @date: 2024/6/23 19:58
 */
@RestController
@Api(tags = "鱼的种类查询接口")
@Slf4j
public class FishTypeController {

    private final FishTypeService fishTypeService;

    public FishTypeController(FishTypeService fishTypeService) {
        this.fishTypeService = fishTypeService;
    }

    /**
     * 查询所有种类
     *
     * @return
     */
    @ApiOperation("查询鱼的种类")
    @GetMapping("/getFishNameAndType")
    public JSONObject getFishNameAndType() {
        JSONObject result = new JSONObject();
        List<FishType> allFishType = fishTypeService.findAllTypeByStationName();
        if (CollectionUtils.isEmpty(allFishType)) {
            log.error("没有种类数据");
            result.put("status", false);
            result.put("data", null);
            return result;
        }

        log.info("查询种类成功");
        result.put("status", true);
        result.put("data", allFishType);
        return result;
    }
}
